package com.shihb.behavioralpatterns.iteratorpattern;

import java.util.Iterator;

/**
 *Description:迭代器模式
 *Version:1.0.0
 *@author shihb
 *@date 2020/4/21 11:23
 */
public class Client {

  public static void main(String[] args) {

    CollegeAggregation computerAggregation = new ComputerAggregation();
    CollegeAggregation infoAggregation = new InfoAggregation();
    System.out.println("======="+computerAggregation.getName()+"========");
    printDepartment(computerAggregation);
    System.out.println("======="+infoAggregation.getName()+"========");
    printDepartment(infoAggregation);

  }

  private static void printDepartment(CollegeAggregation aggregation) {
    Iterator iterator = aggregation.create();
    while(iterator.hasNext()){
      Department next = (Department) iterator.next();
      System.out.println(next.getName());
    }
  }
}
